package com.sgb.goods.view.adapter.order;

import android.text.TextUtils;

import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.databinding.GoodsItemLogisticsAgreementBinding;
import com.sgb.goods.entity.order.LogisticsAgreementEntity;
import com.sgb.goods.utils.base.adapter.BaseCommonAdapter;

/**
 * 描述：商品订单中的物流约定
 * 列表数据适配器
 *
 * @author qiangHeNoo
 * <p>
 * 时间：2021.12.16
 */
public class LogisticsAgreementAdapter extends BaseCommonAdapter<LogisticsAgreementEntity> {

    public LogisticsAgreementAdapter() {
        super(R.layout.goods_item_logistics_agreement, BR.entity);
    }

    @Override
    protected void convert(BaseViewHolder baseHolder, ViewDataBinding dataBinding, LogisticsAgreementEntity entity) {
        GoodsItemLogisticsAgreementBinding binding = (GoodsItemLogisticsAgreementBinding) dataBinding;
        binding.tvRequire.setText(getRequire(entity));
    }

    private String getRequire(LogisticsAgreementEntity entity) {
        String shippingWay = entity.shippingWay;
        if (TextUtils.isEmpty(shippingWay)) {
            return "/";
        }
        int length = shippingWay.trim().length();
        StringBuilder stringBuilder = new StringBuilder(shippingWay);
        if (length == 6) {
            stringBuilder.insert(4, "\n");
        } else if (length > 6 && length <= 10) {
            stringBuilder.insert(5, "\n");
        } else if (length > 10 && length <= 12) {
            stringBuilder.insert(5, "\n");
            stringBuilder.insert(11, "\n");
        }
        return stringBuilder.toString();
    }

}
